// pages/bbs/detail/detail.js
import host from "../../../utils/config"
import wxapi from "../../../utils/wxapi"
Page({

  /**
   * 页面的初始数据
   */
  data: {
    main:{},

    showdetail:true ,//默认为ture

    comment:[ ],

    stared: 0,
    comValue: "",
    
      // {id:2, time: "6个月", money: 300},
      // {id:3, time: "1年", money: 600},
     

  },

  addstar(){
    var s = this.data.main.star;
    var sd = this.data.stared;
    //console.log(s);
    if(sd==0){
      this.setData({
        stared: s+1,
      });
    }
    else{
      this.setData({
        stared: 0,
      });
    }
    //console.log(this.data.stared);
  },

  ValueInput:function(e){
    var value=e.detail.value;
    //comment
    this.setData({
      comValue:value,
    })
    // console.log(this.data.comValue);
  },

  sent:function(e){
    var value = e.currentTarget.dataset.value;
    console.log("value: " + value);
    // console.log("value1: " + value1);
    // console.log("value2: "+value2);
    // if(value1 == undefined)
    // {
    //   var value = value2;
    // }
    // else
    // {
    //   var value = value1;
    // }
    this.setData({
      comValue: value,
    })
    console.log("comValue: " + this.data.comValue);

    var that = this;
    setTimeout(function () {
      that.setData({
        comValue:' '
      })
    },500)

    wx.showToast({
      title: '发送成功',
      icon: "success",
      duration: 2000
    })

  },
  

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad:async function (options) {
    let xq = JSON.parse(options.xiangqing);
    this.data.main = xq;
    this.setData({
      main: xq
    })
    console.log(this.data.main.id)

    if(this.data.main.id != null)
    {
      let a=await wxapi.request(host+"jqquery.php",
      {
        table: "forum_topic_back",
        valuename: "topic_id",
        value: this.data.main.id,
      })

      this.setData({
        comment: a.data.dataList
      })

      console.log(a.data.dataList)
    }
  
 
    // if(this.data.main.id != null){
    //   this.data.showdetail = true;
    // }
    // else{
    //   this.data.showdetail = false;
    // }
    console.log(xq);

    
  },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})